<?xml version="1.0" encoding="utf-8"?>
<openerp>
	<data>

		<record id="view_sales_order_filter_applico" model="ir.ui.view">
			<field name="name">sale.order.list.select.applico</field>
			<field name="model">sale.order</field>
			<field name="inherit_id" ref="sale.view_sales_order_filter"/>
			<field name="arch" type="xml">
				<filter string="Done" position="replace">
					<filter string="Non Cancel" domain="[('state','!=','cancel')]" name="non_cancel_so" help="Sales Order not in Cancel"/>
					<filter string="Done" domain="[('state','=','progress')]" help="Sales Order done"/>
				</filter>
			</field>
		</record>
		<record id="sale.action_quotations" model="ir.actions.act_window">
			<field name="context">{
				'search_default_my_sale_orders_filter': 1,
				'search_default_non_cancel_so': 1,
				}
			</field>
		</record>

		<record id="view_order_form_applico" model="ir.ui.view">
			<field name="name">sale.order.form.applico</field>
			<field name="model">sale.order</field>
			<field name="inherit_id" ref="sale.view_order_form"/>
			<field name="arch" type="xml">
				<button name="%(sale.action_view_sale_advance_payment_inv)d" position="replace">
					<button name="%(sale.action_view_sale_advance_payment_inv)d" string="Create Invoice"
                            type="action" states="manual" class="oe_highlight" groups="base.group_sale_manager"/>
				</button>
				<button name="cancel" position="replace">
					<button name="cancel" states="draft,sent" string="Cancel Quotation" groups="base.group_sale_manager"/>
				</button>
				<button name="action_cancel" position="replace">
					<button name="action_cancel" states="manual,progress" string="Cancel Order" type="object" groups="base.group_sale_manager"/>
				</button>
				<button name="copy_quotation" position="replace">
					<button name="copy_quotation" states="cancel" string="New Copy of Quotation" type="object" groups="base.group_sale_manager"/>
				</button>
				<button name="action_view_invoice" position="replace">
					<button name="action_view_invoice" string="View Invoice" type="object" class="oe_highlight"
						invisible="1" groups="base.group_user"/>
				</button>
				<button name="copy_quotation" position="after">
					<button name="action_cancel_draft" states="cancel" string="Set To Draft" type="object" groups="base.group_sale_manager"/>
				</button>
				<field name = "state" position="replace">
					<field name="state" widget="statusbar" statusbar_visible="draft,progress" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
				</field>
				<xpath expr="//notebook/page[@string='Order Lines']/field[@name='order_line']/tree/field[@name='price_subtotal']" position="after">
					<button name="%(edit_qty_so_line_act)d" string="Edit Qty" type="action" groups="base.group_sale_manager" icon="gtk-go-forward" states="confirmed"/>
					<button name="%(act_delete_so_line)d" string="Delete Line" type="action" groups="base.group_sale_manager" icon="gtk-cancel" states="confirmed"/>
				</xpath>
				
				<page string="Other Information" position="after">
					<page string="Other Setup">
						<group>
							<button type="action"
	                            name="%(act_add_lines_so)d"
	                            class="oe_stat_button"
	                            icon="fa-sign-in"
	                            groups="base.group_sale_manager"
	                            string="Add SO Line" states="progress">
	                        </button>
						</group>
					</page>
				</page>
			</field>
		</record>

		<record id="view_order_form_inherit_applico" model="ir.ui.view">
			<field name="name">sale.order.form.sale.stock.applico</field>
			<field name="model">sale.order</field>
			<field name="inherit_id" ref="sale_stock.view_order_form_inherit"/>
			<field name="arch" type="xml">
				<field name="picking_policy" position="replace">
					<field name="picking_policy" required="True" invisible="1"/>
					<field name="invoice_date"/>
					<field name="do_date"/>
					<field name="other_policy" required="True"/>
				</field>
				<button name="action_view_delivery" position="replace">
					<button type="object"
						name="recreate_picking"
						string="Recreate Delivery Order" class="oe_highlight" states="progress,manual"/>
					<button type="object"
							name="revert_invoice"
							string="Revert to 'Make To Invoice'" class="oe_highlight" attrs="{'invisible': ['|',('state', 'not in', ('progress')),('order_policy', 'not in', ('manual'))]}" groups="base.group_sale_manager"/>
					<!--button name="action_view_delivery" string="View Delivery Order" type="object" class="oe_highlight"
						attrs="{'invisible': [('state', 'not in', ('progress','manual'))]}" groups="base.group_user"/-->

				</button>
				<xpath expr="//sheet/h1" position="after">
					<div class="oe_right oe_button_box" name="buttons">
						<button type="object"
							name="action_view_delivery"
							class="oe_stat_button"
							icon="fa-truck"
							attrs="{'invisible': [('state', 'not in', ('progress','manual'))]}" groups="base.group_user">
							<field name="do_count" widget="statinfo" string="Out Deliverys" help="Delivery Orders"/>
						</button>
						<button type="object"  name="action_view_invoice"
							class="oe_stat_button"
							icon="fa-pencil-square-o"
							attrs="{'invisible': [('invoice_exists', '=', False)]}" groups="base.group_user">
							<field name="invoice_count" widget="statinfo" string="Invoices" help="Invoices"/>
						</button> 

					</div>
				</xpath>
			</field>
		</record>
		<delete model="ir.values" search="[('name','=','Make Invoices'),('model','=','sale.order.line')]"/>

		<record id="view_order_line_form2_applico" model="ir.ui.view">
			<field name="name">sale.order.line.form2.applico</field>
			<field name="model">sale.order.line</field>
			<field name="inherit_id" ref="sale.view_order_line_form2"/>
			<field name="arch" type="xml">
				<button name ="%(sale.action_view_sale_order_line_make_invoice)d" position="replace">
					<button name="%(sale.action_view_sale_order_line_make_invoice)d" invisible ="1" string="Create Invoice" type="action" class="oe_highlight" groups="base.group_sale_manager"/>
				</button>
				<button name ="button_cancel" position="replace">
					<button name="button_cancel" string="Cancel Line" type="object" invisible ="1" states="confirmed,exception" groups="base.group_user"/>
				</button>
				<button name ="button_done" position="replace">
					<button name="button_done" string="Done" type="object" invisible="1" class="oe_highlight" groups="base.group_user"/>
				</button>
				<field name ="order_id" position="replace">
					<field name="order_id" domain="[('state','!=','done')]" readonly="1"/>
				</field>
				<field name ="order_partner_id" position="replace">
					<field name="order_partner_id" readonly="1"/>
				</field>
				<field name ="product_id" position="replace">
					<field name="product_id" readonly="1"/>
				</field>
				<field name ="product_uom" position="replace">
					<field name="product_uom" readonly="1" groups="product.group_uom" class="oe_inline"/>
				</field>
				<field name ="price_unit" position="replace">
					<field name="price_unit" readonly="1"/>
				</field>
				<field name ="name" position="replace">
					<field name="name" readonly="1"/>
				</field>
			</field>
		</record>

	</data>
</openerp>
